<template>
	<view class="page">
		<image src="/static/login_bg_title.png" mode="widthFix" style="height: 100%;"></image>
		<view style="position: fixed; top: 0rpx; padding-top: 100rpx; width: 100%;">
			<span style="font-weight: bold; font-size: 64rpx; margin-left: 60rpx;">登录</span>
			<view style="margin-left: 40rpx; margin-right: 40rpx; margin-top: 40rpx;">
				<u-button type="text" ripple size="default" @click="login()">登录</u-button>
			</view>
			<view style="flex-direction: row; margin: 20rpx auto;">
				<checkbox :checked="agree" @click="agreeChange" color="#3964e6"
					style="transform: scale(0.55) translate(50px,-5px); width: 60px; margin-left: -10%;">
				</checkbox>
				<view style="font-size: 20rpx;" @click="agreeChange">登录即代表您已阅读并同意</view>
				<view style="font-size: 20rpx; color: #8d8d8d; margin-left: 10rpx;"
					@click="open_url('/pages/biz/protocol')">
					《用户协议》
				</view>
				<view style="font-size: 20rpx;">和</view>
				<view style="font-size: 20rpx; color: #8d8d8d; margin-left: 10rpx;"
					@click="open_url('/pages/biz/secrecy')">
					《隐私政策》
				</view>
			</view>
			<view style="margin-top: 50rpx; width: 100%;">
				<u-divider bg-color="#00000000" border-color="#00aa00" half-width="220">第三方账号登录</u-divider>
				<view style="margin: 30rpx auto;" @click="getWeChatCode" v-if="isWeixin">
					<u-icon name="weixin-fill" color="#00aa00" size="100"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				login_phone: '',
				login_password: '',
				isWeixin: false,
				agree: false,
				animation: '',
			}
		},
		methods: {
			getWeChatCode() {
				if (!this.agree) {
					uni.showToast({
						title: '请勾选同意协议',
						icon: 'none'
					});
					return
				}
			
				var self = this
				wx.login({
					success: (loginRes) => {
						console.log("微信登录", loginRes);
						uni.request({
							url: getApp().globalData.base_url + '/api/public/getWechatOpenId',
							method: 'GET',
							data: {
								code: loginRes.code
							},
							header: {
								'Content-Type': 'application/json;charset=UTF-8' //自定义请求头信息
							},
							success: (res) => {
								console.log("getOpenId", res.data)
								if (res.data.success) {
									uni.showModal({
										title: '温馨提示',
										content: '亲，授权微信登录后才能正常使用小程序功能',
										success(modalRes) {
											wx.getUserProfile({
												desc: "获取你的昵称、头像、地区及性别",
												success: userProfileRes => {
													console.log(
														userProfileRes)
													let wxUserInfo =
														userProfileRes
														.userInfo
													wxUserInfo.openid = res
														.data.data
													console.log(
														"wxUserInfo",
														wxUserInfo)
													self.loginWx(
														wxUserInfo)
												},
												fail: res => {
													console.log("授权失败")
												}
											})
										}
									})
								}
							},
							complete: () => {
			
							}
						})
					},
				})
			},
		}
	}
</script>

<style>

</style>
